package threaddemo16;

import java.util.concurrent.ArrayBlockingQueue;

/**
 * Created by L.jp
 * Description:
 * User: 86189
 * Date: 2022-08-07
 * Time: 17:35
 */
//阻塞队列实现等待唤醒机制
    /*
生产者类(Cooker)：继承Thread类，重写run()方法，设置线程任务
1.构造方法中接收一个阻塞队列对象
2.在run方法中循环向阻塞队列中添加包子
3.打印添加结果
*/
public class Cooker extends Thread {
    private ArrayBlockingQueue<String> aq;
    
    public Cooker(ArrayBlockingQueue<String> aq) {
        this.aq = aq;
    }
    
    @Override
    public void run() {
        while (true) {
            //做包子就是完往阻塞队列里面放包子
            try {
                aq.put("包子");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("厨师做了一个包子");
        }
    
    }
}
